package org.example.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

/**
 * @author woopsion
 * @date 2025-07-05
 */
@Configuration
public class RabbitMqSeckillConfig {
    public static final String QUEUE = "SeckillQueue";
    public static final String EXCHANGE_SECKILL = "SeckillExchange";

    @Bean
    public Queue queue_seckill() {
        return new Queue(QUEUE);
    }

    /**
     * 创建topic类型 交换机
     * @return
     */
    @Bean
    public TopicExchange exchange_seckill() {
        return new TopicExchange(EXCHANGE_SECKILL);
    }

    /**
     * 绑定Queue 到 SECKILL TOPIC-EXCHANGE
     * @return
     */
    @Bean
    public Binding binding_seckill() {
        return BindingBuilder.bind(queue_seckill())
                .to(exchange_seckill())
                .with("seckill.#");
    }
}
